<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div class="r_location">
	<i class="r_txtico"></i> 用户信息管理 &gt; 贴士发送管理
</div>

<form id="qForm" action="#">
	<ul class="all_list">
		<li><span class="all_title">发送日期：</span> <span>
		<input type="text" id="displayDateFrom" name="displayDateFrom" class="ui_input datepicker Wdate" group='{"group": {"startId":"displayDateFrom", "endId":"displayDateTo","showNext": true}}' option='start-auto-end' /> - <input type="text" id="displayDateTo" name="displayDateTo"  class="ui_input datepicker Wdate" option='start-auto-end'/>
		<!-- <input
				type="text" class="ui_input Wdate" id="displayDateFrom"
				name="displayDateFrom"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'displayDateTo\')}'})">
				- <input type="text" class="ui_input Wdate" id="displayDateTo"
				name="displayDateTo"
				onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'displayDateFrom\')}'})"> --></span></li>

		<li><span class="all_title">通知对象：</span> <span><select
				id="roleId" name="roleId" class="ui_input">
					<option value=""></option>
					<c:forEach var="role" items="${roles}">
						<option value="${role.id}">${role.name}</option>
					</c:forEach>
			</select></span></li>
		<li><span class="all_title"></span><span> <input
				type="button" id="query" value="查询" class="search_btn m-r15 submitBtn">
				<input id="reset" class="reset_btn" type="reset" name="button" value="重 置">
		</span></li>
	</ul>
</form>

<shiro:hasPermission name="tips:add">
<div style="margin-bottom: 5px;">
	<!-- <button id="tips_add" class="btn_big">新建贴士</button> -->
	<a class="auto_black_btn" id="tips_add" href="#" ><span>新建贴士</span></a>
</div>
</shiro:hasPermission>

<div class="m-t10">
	<div class="table_fn clearfix"><span class="l">贴士列表</span></div>
	<table id="tips_table">
	</table>
	<div id="pgtoolbar"></div>
</div>
<script>

$.datepicker();
	function hide_tips(id){
		art.dialog({
			title : '隐藏贴士',
			lock : true,
			content : '确认隐藏贴士?',
			width : '200px',
		    cancelVal: '关闭',
		    cancel: true,
			ok : function () {
				$.post("tips/hide", {id:id}, function(data) {
					if(data.code!="01"){
						$("#tips_table").jqGrid("setGridParam", {
							datatype : "json"
						}).trigger("reloadGrid", [ {
						} ]);
					} else {
						art.dialog({icon: data.success,content: data.message,lock:true});
					}
				});
			}
		});
	}
	function edit_tips(id) {
		to_page('/tips/edit/' + id);
	}
	$(function() {
		$.jgrid.ajaxOptions.type = 'post';
		$("#tips_table").jqGrid({
			url : "tips/view",
			datatype : "json",
			colModel : [ {
				label : '显示日期',
				name : 'displayDate',
				index : 'displayDate',
				width : 60,
				formatter:function(cell,options,row){
					return to_date(row.displayDateFrom) + ' 至 ' + to_date(row.displayDateTo);
				}				
			}, {
				label : '持续时间(秒)',
				name : 'displayTime',
				index : 'displayTime',
				width : 30
			}, {
				label : '显示次数',
				name : 'displayCount',
				index : 'displayCount',
				width : 20
			}, {
				label : '贴士内容',
				name : 'content',
				index : 'content',
				align : 'left',
				width: 100
			}, {
				label : '通知对象',
				name : 'roleList',
				index : 'roleList',
				align : 'left',
				formatter:function(cell,options,row){
					var result = new Array;
					for(var i=0;i<cell.length;i++){
						result[i] = cell[i].name;
					}
					return result.join(';');
				},
				width : 80
			}, {
				label : '操作',
				name : 'operation',
				index : 'operation',
				width: 30,
				formatter:function(cell,options,row){
					var result = '';
					var isHide = row.isHide;
					if(!isHide){
						<shiro:hasPermission name="tips:hide">
							result += '<a href="#" onclick="edit_tips(\''+row.id+'\')">修改</a> ';
						</shiro:hasPermission>
						<shiro:hasPermission name="tips:hide">
							result += '<a href="#" onclick="hide_tips(\''+row.id+'\')">隐藏</a>';
						</shiro:hasPermission>
					}else{
						result = '已隐藏';
					}
					return result;
				}
			}],
			height : 370,
			rowNum : 10,
			rowList : [ 10, 20, 30 ],
			viewrecords : true,
			pager : '#pgtoolbar',
			autowidth : true,
			rownumbers : true,
			jsonReader : {
				root : "data",//当前记录
				page : "index",
				records : "totalRecord",//总记录数
				total : 'total',//总页数
				id : 'data.id',
				repeatitems : false
			}
		});
		$("#query").click(function() {
			var param = {
					displayDateFrom : $("#displayDateFrom").val(),
					displayDateTo : $("#displayDateTo").val(),
					roleId : $("#roleId").val()
			};
			var postData = $("#tips_table").jqGrid("getGridParam","postData");
			$.extend(postData, param);
			$("#tips_table").jqGrid("setGridParam", {
				datatype : "json"
			}).trigger("reloadGrid", [ {
				page : 1
			} ]);
		});
		$("#tips_add").click(function() {
			<shiro:hasPermission name="tips:add">
			to_page('/tips/add/page');
			</shiro:hasPermission>
		});
	});
</script>